<?php 
function sendAskConfirmationMail() {

  global $name1;
  global $email;
  global $selected_date;
  global $selected_date_nl;
  global $selected_start_time;
  global $confirm_url;
  global $reservation_id;
  global $guid;
  global $confirm_page;
  global $mail_template;
  global $location_name;
  
  if (isset($name1) && !empty($name1)) { 
    $selected_name = $name1." (".$email.")"; 
  } else { 
    $selected_name = $email;
  }
  
  // /example.php
  $pattern = "/^(.*)([\/][\d][\d][_].*[\.]php)(.*)$/";
  $replacement = "$1/$confirm_page$3";
  $confirm_url = preg_replace($pattern, $replacement, curPageURL());  
  $confirm_url = $confirm_url."?reservation_id=$reservation_id&guid=$guid";
  
  // multiple recipients
  $to  = $email;

  // subject
  $subject = 'Definitief maken reservering';

  // message
  $message = get_include_contents($mail_template);
  $message = str_replace("#selected_name", $selected_name, $message);
  $message = str_replace("#selected_date_nl", $selected_date_nl, $message);
  $message = str_replace("#selected_start_time", $selected_start_time, $message);
  $message = str_replace("#location_name", $location_name, $message);
  $message = str_replace("#confirm_url", $confirm_url, $message);

  // To send HTML mail, the Content-type header must be set
  $headers  = "MIME-Version: 1.0" . "\r\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

  // Additional headers
  $headers .= "To: $email" . "\r\n";
  $headers .= "Bcc: info@redjezaterdag.nl" . "\r\n";
  $headers .= "From: No Reply <no_reply@redjezaterdag.nl>" . "\r\n";

  // Mail it
  if (mail($to, $subject, $message, $headers)) {
    //echo "Success mail send";
    $error = null;
  } else {
    //echo $error; 
    echo "Error mail not send";
    $error = (isset($php_errormsg))? $php_errormsg : '';
  }
}



function pinConfirmationMail() {

  global $name1;
  global $email;
  global $selected_date;
  global $selected_date_nl;
  global $selected_start_time;
  
  if (isset($name1) && !empty($name1)) { 
    $selected_name = $name1." (".$email.")"; 
  } else { 
    $selected_name = $email;
  }
 
  // multiple recipients
  $to  = $email;

  // subject
  $subject = 'Je PIN betaling is bevestigd';

  // message
  $message = get_include_contents("common/mail.pin.message.html");
  $message = str_replace("#selected_name", $selected_name, $message);
  $message = str_replace("#selected_date_nl", $selected_date_nl, $message);
  $message = str_replace("#selected_start_time", $selected_start_time, $message);

  // To send HTML mail, the Content-type header must be set
  $headers  = "MIME-Version: 1.0" . "\r\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";

  // Additional headers
  $headers .= "To: $email" . "\r\n";
  $headers .= "From: No Reply <no_reply@redjezaterdag.nl>" . "\r\n";

  // Mail it
  if (mail($to, $subject, $message, $headers)) {
    //echo "Success mail send";
    $error = null;
  } else {
    echo "Error mail not send";
    $error = (isset($php_errormsg))? $php_errormsg : '';
    //echo $error; 
  }

}

?>
